<?php
require_once NINA_ROOT . DIRECTORY_SEPARATOR . 'jpgraph' . DIRECTORY_SEPARATOR . 'jpgraph.php';
require_once NINA_ROOT . DIRECTORY_SEPARATOR . 'jpgraph' . DIRECTORY_SEPARATOR . 'jpgraph_scatter.php';

/**
 * JPGraph Scatter Chart Wrapper
 * @package Nina
 * @author John Main <john@thedaddy.org>
 */
class Nina_Graph_Jpgraph_Scatter extends Nina_Graph_Jpgraph_Plot
{
	/**
	 * Contructor
	 * @param integer [$width=400] The width
	 * @param integer [$height=400] The height
	 */
	public function __construct($width = 400, $height = 400) {
		$this->graph = new Graph($width, $height);
		$this->graph->setMargin(50, 10, 10, 40);
		$this->plot = new ScatterPlotExtended(array());

		parent::__construct();
	}

	/**
	 * Set the colour
	 * @param string color The colour
	 */
	function setColor($color) {
		$this->linkPoints($color);
	}

	/**
	 * Link the points with a line
	 * @param string [$color='black'] The line color
	 * @param integer [$weight=1] The line weight
	 * @param string [$style='solid'] The line style
	 */
	public function linkPoints($color = 'black', $weight = 1, $style = 'solid') {
		$this->plot->SetLinkPoints(true, $color, $weight, $style);
	}
}

/**
 * JPGraph Scatter Chart Extension
 * Adds ability to set data outside of the constructor
 * @package Nina
 * @author John Main <john@thedaddy.org>
 */
class ScatterPlotExtended extends ScatterPlot {

	/**
	 * Parent constructor doesn't work unless we start with some data
	 * @param array [$datax=null] The x axis data
	 * @param array [$datay=null] The y axis data
	 */
	public function __construct($datax = null, $datay = null) {
		if(!$datax)
			$datax = array(1);

		if(!$datay)
			$datay = array(1);

		parent::__construct($datax, $datay);
	}

	/**
	 * Set the plot data
	 * @param array $datax The x-axis data
	 * @param array $datay The y-axis data
	 */
	function setData($datax, $datay) {
		$this->inputValues = array();
		$this->inputValues['aDatay'] = $datax;
		$this->inputValues['aDatax'] = $datay;

		$this->coords[0] = $datay;
		$this->coords[1] = $datax;
		$this->numpoints = count($datax);
	}
}
